package com.itheima.homework;

import java.awt.font.FontRenderContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * 4 题目
 * 	统计字符串中每一个字符的出现个数
 * 	例如:字符串”aabbccdd”
 * 输出结果为:a(2)b(2)c(2)d(2)
 */
public class Test4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String s = sc.next();
//        ArrayList<Character> list = new ArrayList<>();
//        for(int i = 0; i < s.length(); i++) {
//          char c =  s.charAt(i);
//          list.add(c);
//        }
//        System.out.println(list);
//
//        TreeSet<Character> ts = new TreeSet<>(list);
        String[] strs = s.split("");
        //使用split切割字符
       // System.out.println(Arrays.asList(strs));
        ArrayList<String> list = new ArrayList<>(Arrays.asList(strs));

        TreeSet<String> ts = new TreeSet<>(list);


        System.out.println(ts);
        for (String t : ts) {
            int count = 0;
            for (int i = 0; i < strs.length; i++) {
                if (t.contains(strs[i])){
                    count++;
                }
            }
            System.out.print( t + "(" + count +")" + "  ");
        }
//        for (Character t : ts) {
//            int count =0;
//            while (list.remove(t)){
//                count++;
//            }
//            System.out.print( t + "(" + count +")");
//        }
    }
}
